package cn.com.ninng;

import java.util.Arrays;
import java.util.List;

/**
 * 字符串最长公共前缀
 *
 * @author liulekang
 * @createdate 2021/7/28
 */
public class Problem14 {

    public static void main(String[] args) {
        System.out.println(longestCommonPrefix(new String[]{"flow","fl",
                "floweraasd"}));
    }


    public static String longestCommonPrefix(String[] strs) {


        for (int i =0; i < strs[0].length();i++) {
            char charAt = strs[0].charAt(i);
            for (int j = 1;j < strs.length;j++){
                if (strs[j].length() == i || strs[j].charAt(i) != charAt) {
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }
}
